package com.banana.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PatternUtil {

	public static final String[] getPatternGroup(Pattern pattern , String string){
		Matcher matcher = pattern.matcher(string);
		if (matcher.find()){
			String[] result = new String[matcher.groupCount()+1];
			for (int i = 0; i < result.length; i++) {
				result[i] = matcher.group(i);
			}
			return result;
		}
		
		return new String[]{};
	}
	
	public static final String getPatternIndexByGroup(Pattern pattern , String string,int index){
		String[] result = getPatternGroup(pattern, string);
		if (result.length > index){
			return result[index];
		}
		return "";
	}
	
}
